﻿using System;
using System.Web.Mvc;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Rhino.Mocks;
using ScrumBox.Model;
using ScrumBox.Web.Controllers;
using MvcContrib;

namespace ScrumBox.UnitTests.Website
{
    [TestFixture]
    public class ProjectControllerTester
    {
        private MockRepository _mocks;
        private Project _project;
        private IProjectRepository _projectRepository;
        
        private const string projectKey = "MyProject";
        private const string projectName = "MyProject";

        [SetUp]
        public void Setup()
        {
            _mocks = new MockRepository();
            _projectRepository = _mocks.DynamicMock<IProjectRepository>();
            _project = new Project(projectName, projectKey, DateTime.Now);
        }

        [Test]
        public void ShouldGetProjectToShowDetails()
        {
            using (_mocks.Record())
            {
                SetupResult.For(_projectRepository.GetByKey(projectKey)).Return(_project);
            }

            using (_mocks.Playback())
            {
                var controller = new ProjectController(_projectRepository);
                var actionResult = controller.Details(projectKey) as ViewResult;

                if (actionResult == null)
                    Assert.Fail("expected a renderview");

                Assert.That(actionResult.ViewName, Is.Null);

                var viewProject = controller.ViewData.Get<Project>();
                Assert.That(viewProject, Is.Not.Null);
                Assert.That(viewProject, Is.EqualTo(_project));
            }

        }

    }
}